package com.xmall.auth.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xmall.auth.dao.SysAdminPermissionRelationMapper;
import com.xmall.auth.entity.SysAdminPermissionRelation;
import com.xmall.auth.service.ISysAdminPermissionRelationService;
import com.xmall.common.config.PlatformContant;
import com.xmall.common.config.PojoUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 后台用户和权限关系表(除角色中定义的权限以外的加减权限) 服务实现类
 * </p>
 *
 * @author liuzh
 * @since 2020-06-14
 */
@Service
public class SysAdminPermissionRelationServiceImpl extends ServiceImpl<SysAdminPermissionRelationMapper, SysAdminPermissionRelation> implements ISysAdminPermissionRelationService {
    @Autowired
    SysAdminPermissionRelationMapper sysAdminPermissionRelationMapper;

    @Override
    public boolean saveSysAdminPermissionRelation(SysAdminPermissionRelation sysAdminPermissionRelation) {
        PojoUtils.setSysProperties(sysAdminPermissionRelation, PlatformContant.OpType.insert);
        return save(sysAdminPermissionRelation);
    }

    @Override
    public boolean updateSysAdminPermissionRelation(Long id, SysAdminPermissionRelation sysAdminPermissionRelation) {
        SysAdminPermissionRelation oldSysAdminPermissionRelation = getById(id);
        BeanUtils.copyProperties(sysAdminPermissionRelation, oldSysAdminPermissionRelation);
        PojoUtils.setSysProperties(oldSysAdminPermissionRelation, PlatformContant.OpType.update);
        boolean update = update(
                oldSysAdminPermissionRelation,
                new QueryWrapper<SysAdminPermissionRelation>()
                        .lambda().eq(SysAdminPermissionRelation::getId, id)
        );
        return update;
    }

    @Override
    public boolean deleteSysAdminPermissionRelation(Long id) {
        boolean b = removeById(id);
        return b;
    }

    @Override
    public SysAdminPermissionRelation getSysAdminPermissionRelation(Long id) {
        SysAdminPermissionRelation sysAdminPermissionRelation = getById(id);
        return sysAdminPermissionRelation;
    }
}
